package com.huayue.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.support.spring.FastJsonJsonView;
import com.huayue.annotation.LogAnno;
import com.huayue.entity.Product;
import com.huayue.service.ProductService;
import com.huayue.service.ProductTypeService;
import com.huayue.service.SupplierService;
import com.huayue.util.PageHelper;

/**
 * 商品
 * 
 */
@Controller
@RequestMapping("/product")
public class ProductController {
    @Autowired
    ProductService svc;

    @Autowired
    SupplierService supplierService;

    @Autowired
    ProductTypeService productTypeService;

    BaseController bc = new BaseController();

    @LogAnno(operateType = "添加-商品信息")
    @RequestMapping("/add")
    public ModelAndView add(Product product) {
        return bc.add(svc, product);
    }

    @LogAnno(operateType = "修改-商品信息")
    @RequestMapping("/update")
    public ModelAndView update(Product product) {
        return bc.update(svc, product);
    }

    @LogAnno(operateType = "删除-商品信息")
    @RequestMapping("/delete")
    public ModelAndView delete(Product product) {
        return bc.delete(svc, product);
    }

    @RequestMapping("/findOne")
    public ModelAndView findOne(Product product) {
        return bc.findOne(svc, product);
    }

    @RequestMapping("/findTerm")
    public ModelAndView findTerm() {
        FastJsonJsonView view = new FastJsonJsonView();
        view.addStaticAttribute("status", 200);
        view.addStaticAttribute("productType", productTypeService.findAll());
        view.addStaticAttribute("supplierType", supplierService.findAll());

        return new ModelAndView(view);
    }

    @RequestMapping("/findPage")
    public ModelAndView findPage(PageHelper page, Product product) {
        return bc.findPage(svc, page, product, product);
    }
}
